<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
    </head>
    <body>
		<?php
		/*
		 * This script is used for parse  a xml file about Cis regulatory region
		 * it shows the duplicates stable_gene_identifier clusters used in the xml file
		 * We use for that a csv file named "clustertogene.csv"
		 */

		$doublon = array();
		$arrResult = array();
		$arrLines = file('clustertogene.csv');
//		$arrLines = file('your csv file.csv');
		foreach ($arrLines as $line) {
			$tmp = explode(';', $line);
			/*
			 * si tmp[1] c'est à dire le cluster.... existe déja, on le met à la suite
			 * de celui-ci, on utilise ensuite le tableau doublon pour référencer uniquement les doublons
			 */
			if (array_key_exists(trim($tmp[1]), $arrResult)) {
				$arrResult[trim($tmp[1])] = $arrResult[trim($tmp[1])] . "/" . trim($tmp[0]);
				$doublon[trim($tmp[1])] = $arrResult[trim($tmp[1])];
			} else {
				$arrResult[trim($tmp[1])] = trim($tmp[0]);
			}
		}

		$dom = new DOMDocument();
//		$dom->load('RegulatoryRegions_ciona_intestinalis.xml');
		$dom->load('RegulatoryRegions_old.xml');
                print_r("Duplicates clusters from STABLE GENE IDENTIFIER<br /><br />");
		$elts = $dom->getElementsByTagName('stable_gene_identifier');

		$alreadyUsed = array();
		foreach ($elts as $elt) {

			$tmp = trim($elt->nodeValue);

			if (!in_array($tmp, $alreadyUsed)) {
				if (array_key_exists($tmp, $doublon)) {
					print_r($tmp . " : " . $doublon[$tmp]);
					print_r("<br />");
					$alreadyUsed[] = $tmp;
				}
			}
		}

//		$dom->save('testintegration.xml');
//		$dom->save('your xml destination.xml');
		?>
    </body>
</html>
